package com.example.administrator.rxjavarxandroid_retrofit.mvp.presenter;

import android.app.Activity;
import android.content.Context;

import com.example.administrator.rxjavarxandroid_retrofit.base.BasePresenter;
import com.example.administrator.rxjavarxandroid_retrofit.http.api.CommonApi;
import com.example.administrator.rxjavarxandroid_retrofit.http.rxjava.HttpObserver;
import com.example.administrator.rxjavarxandroid_retrofit.mvp.contract.MainContract;
import com.example.administrator.rxjavarxandroid_retrofit.mvp.model.MainModel;
import com.example.administrator.rxjavarxandroid_retrofit.pojo.TableIp;

import java.lang.ref.WeakReference;

import javax.inject.Inject;

/**
 * Created by chenboge on 2016/12/18.
 */
public class MainPresenter extends BasePresenter<MainContract.MainView,MainContract.MainModel> implements MainContract.MainPresenter{


//    在baseactivity中对presenter实例化的时候，找到这个注解构造函数生成实例对象，里面参数通过注解齐内部寻找activity参数和CommonApi参数。
    @Inject
    public MainPresenter(Activity activity, CommonApi commonApi) {
        super(activity,commonApi);
        this.mModel = new MainModel(activity, commonApi);
    }


    @Override
    public void getIpAddress(int page) {
        mModel.getIpAddress(page).subscribe(new HttpObserver<TableIp>(new WeakReference<Context>(mActivity)) {
            @Override
            public void onSuccess(TableIp tableIp) {
                mView.getIpAddressSuccess(tableIp);
            }
        });
    }

}
